<template>
	<div>
		<city-header></city-header>
		<city-search :cities="cities"></city-search>
		<city-list 
			:cities="cities" 
			:hot="hotCities"
			:letter="letter"
			></city-list>
		<city-alphabet :cities="cities" @change="handleletterChange"></city-alphabet>
	</div>

</template>

<script>
	import axios from 'axios';
	import CityHeader from './components/Header.vue';
	import CitySearch from './components/Search.vue';
	import CityList from './components/List.vue';
	import CityAlphabet from './components/Alphabet.vue';
	export default {
		name: 'City',
		data() {
			return {
				cities: {},
				hotCities: [],
				letter: ''
			}
		},
		components: {
			CityHeader,
			CitySearch,
			CityList,
			CityAlphabet
		},
		methods: {
			getCityInfo() {
				axios.get('/api/city.json').then(this.handleGetCityInfoSucc);
			},
			handleGetCityInfoSucc(res) {
				const data = res.data;
				// console.log(res);
				if (data.data && data.ret) {
					// console.log("我进来了");
					this.cities = data.data.cities;
					// console.log(data.data.hotCities)
					this.hotCities = data.data.hotCities;
				}
			},
			
			handleletterChange(letter) {
				// change 事件发生，然后转发给 list 组件
				this.letter = letter
			}
		},
		mounted() {
			this.getCityInfo();
		}
	}
</script>

<style scoped="scoped">
</style>
